TASK_DIR:=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))

include ../config.mk

# Inputs
SRC := $(TASK_DIR)/src/run_regressions.R
FUNCS := $(shell find $(TASK_DIR)/R/ -name '*.R')
CONFIGS := $(shell find $(TASK_DIR)/hand/ -name '*.yaml')
SAMPLE_SETS_CONFIG_FILE := $(TASK_DIR)/hand/sample_sets.yaml
COVARIATE_SETS_CONFIG_FILE := $(TASK_DIR)/hand/covariate_sets.yaml
OUTCOME_SETS_CONFIG_FILE := $(TASK_DIR)/hand/outcome_sets.yaml
SUBGROUPS_CONFIG_FILE := $(TASK_DIR)/hand/subgroups.yaml

# One of the outputs
OUT_FILE := $(OUT_DIR)/regression_results__basic.csv

$(OUT_FILE): $(SRC) $(FUNCS) $(PROJECT_CONFIG) $(CONFIGS) $(XSECTION_ANALYSIS_FILE) $(PANEL_ANALYSIS_FILE)
	@mkdir -p $(OUT_DIR)
	@$(R_script) $(SRC) \
		--PROJECT_CONFIG=$(PROJECT_CONFIG) \
		--TASK_CONFIG=$(TASK_CONFIG) \
		--SAMPLE_SETS_CONFIG_FILE=$(SAMPLE_SETS_CONFIG_FILE) \
		--COVARIATE_SETS_CONFIG_FILE=$(COVARIATE_SETS_CONFIG_FILE) \
		--OUTCOME_SETS_CONFIG_FILE=$(OUTCOME_SETS_CONFIG_FILE) \
		--SUBGROUPS_CONFIG_FILE=$(SUBGROUPS_CONFIG_FILE) \
		--XSECTION_ANALYSIS_FILE=$(XSECTION_ANALYSIS_FILE) \
		--PANEL_ANALYSIS_FILE=$(PANEL_ANALYSIS_FILE) \
		--OUT_DIR=$(OUT_DIR)

.PHONY: all clean
.DEFAULT_GOAL=all

all: $(OUT_FILE)

clean:
	rm -rf $(OUT_DIR)
